<%@page import="com.wef.system.entity.domain.RoleDomain"%>
<%@page import="com.wef.common.util.CommonMessageDomain"%>
<%@include file="/pages/common/taglib.jsp"  %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title></title>
		<%@include file="/styles/css_lib.jsp"%>
		<%@include file="/scripts/widgets/ext-2.2.1/css_lib.jsp"%>
		<%@include file="/scripts/widgets/gfa4ext/css_lib.jsp"%>
		<%@include file="/scripts/widgets/autoSelect/css_lib.jsp"  %>
		
		<%@include file="/pages/common/js_global.jsp"%>
		<%@include file="/scripts/sdk/js_lib.jsp"%>
		<%@include file="/scripts/config/js_lib.jsp"%>
		<%@include file="/scripts/utils/js_lib.jsp"%>
		<%@include file="/scripts/i18n/js_lib.jsp"%>
		<%@include file="/scripts/widgets/ext-2.2.1/js_lib.jsp"%>
		<%@include file="/scripts/widgets/gfa4ext/js_lib.jsp"%>
		<%@include file="/scripts/widgets/autoSelect/js_lib.jsp"%>
		<%@include file="/scripts/widgets/datePicker/js_lib.jsp"%>
		<script type="text/javascript">
			function validateRole(){
				
				return validateRoleEditForm(document.forms[1])&&validateCode();
			}
			
			function validateCode(){
				var errString = '';
				var roleName = $('#roleName').val();
				if(!roleName || roleName == ''){
					errString += String.format(system.Role.roleNameNotNull1);
				} else {
					var roleId = $('#hiddenRoleId').val();
					
						RoleService.validateRoleNameExist(roleName, roleId == ''||!roleId?'':roleId,{
							callback:function(result){
											if(result){
												errString+=String.format(system.Role.roleNameExist1);
											}
										},
							async:false
						});
					
				}
			
				var roleType = $('#roleType').val();
				if(!roleType || roleType == ''){
					errString += String.format(system.Role.activeFlagNotNull1);
				}
				
				var activeDate=$("#datePicker_activeDate").val();
				var expiredDate=$("#datePicker_expiredDate").val();
				if(!activeDate){
					errString += String.format(system.Role.activeDateNotNull1);
				}
				if(!expiredDate){
					errString += String.format(system.Role.expiredDateNotNull1);
				}
						
				if(activeDate > expiredDate){
					errString += String.format(system.Role.expiredDateNotBeforactiveDate1);
				}
				if(errString != ''){
					alert(errString);
					return false;
				}
				return true;
			}
			
			function renderRoleType(value){
				switch(value){
					case '1': return 'Active';
					case '2': return 'Lock';
					case '3': return 'Disable';
				}
			}
			$(window).ready(function(){
				$("#officeCode").autoSelect({
					url : "${ctx}",
					className:"com.wef.system.entity.Office",
					displayField : "officeCode,officeName",
					displayFieldI18n: "system.Office.officeCode,system.Office.officeName",  //显示字段国际化,不需要可不设置
					condition:Gfa.GlobalConstant.CONDITION_LIKE_ANYWHERE_IC,		//查询条件
					width : 450,
					displayNum : 8,
					inTable : false,
					canNotInput:true,	
					hiddenId : 'hiddenOfficeCodeId',
					queryField : "officeCode,officeName"
				});
			});
		</script>
		<ge:body>
			<ge:window id="win">
				<ge:grid.baseGrid 
					queryObjectName="com.wef.system.entity.Role"
					dwrService="RoleService"
					dwrMethod="saveOrUpdateRoles"
					searchFormId="searchForm" 
					editFormId="roleEditForm" 
					searchBtnId="btnSearch"
					saveBtnId="btnSave"
					newBtnId="btnNew"
					deleteBtnId="btnDelete"
					cancelBtnId="btnCancel"
					loadMask="true" 
					id="gridRoleManager"
					bodyStyle="width:100%"
					autoWidth="true"
					height="250"
					allowSelectPageSize="true"
					showExportToExcel="false"
					showExportAllToExcel="false"
					readerFields="roleName,roleDesc,officeCode,activeDate,expiredDate,roleType"
					enableHdMenu="false"
					beforeSaveFunc="validateRole"
					renderTo="gridRoleManager"
					>
					<ge:grid.columnModel>
						<ge:grid.rowNumberer />
						<ge:grid.column header="system.Role.roleName" dataIndex="roleName">
						</ge:grid.column>
						<ge:grid.column header="system.Role.roleDesc" dataIndex="roleDesc" width="300" >
						</ge:grid.column>
						<ge:grid.column header="system.Role.officeCode" dataIndex="officeCode">
						</ge:grid.column>
						<ge:grid.column header="system.Role.activeDate" dataIndex="activeDate" renderer="Ext.util.Format.dateRenderer('Y-m-d')">
						</ge:grid.column>
						<ge:grid.column header="system.Role.expiredDate" dataIndex="expiredDate" renderer="Ext.util.Format.dateRenderer('Y-m-d')">
						</ge:grid.column>
						<ge:grid.column header="system.Role.roleType" dataIndex="roleType" renderer="renderRoleType" >
						</ge:grid.column>
					</ge:grid.columnModel>
				</ge:grid.baseGrid>
			</ge:window>
		</ge:body>
		<%-- <ge:onReady>
			setTimeout(function(){
				gridRoleManager.render('winEL');
			}, 1);
		</ge:onReady> --%>
	</head>
	<body class="body">
	  <!--Content-->
	  <div id="Content">
		<!--Right-->
		<div class="ModuleSearch">
		    <div class="ModuleSearchBorder">
		      <div class="ModuleSearchTitle"><g:label text="title.search" showColon="false" /></div>
		        <form id="searchForm" name="searchForm" onsubmit="return false;">
			      <div class="ModuleSearchInput">
						<table width="100%" cellspacing="0" cellpadding="0">
								<tr>
									<td width="10%"><g:label text="system.Role.roleName"/></td>
									<td width="22%"><g:text property="roleName" condition="likeaic" /></td>
									<td width="10%"><g:label text="system.Role.roleDesc"/></td>
									<td width="22%"><g:text property="roleDesc" condition="likeaic" /></td>
									<td width="10%">&nbsp;</td>
									<td width="22%">&nbsp;</td>
								</tr>
						</table>
		          </div>
		          <div class="ModuleEditButton">
		          	<!--按钮 -->
					<g:button styleId="btnSearch" styleClass="search" type="button" text="button.search"/>
					<!--按钮 -->
					<g:button styleId="btnReset" styleClass="reset" type="reset" text="button.reset"/>
					<!--按钮 -->
				    <g:button styleId="btnNew" styleClass="new" type="button" text="button.new" />
					<!--按钮 -->
				    <g:button disabled="true" styleId="btnSave" styleClass="save" type="button" text="button.save" />
				    <!--按钮 -->
				    <g:button disabled="true" styleId="btnCancel" styleClass="cancel" type="button" text="button.cancel"/>
				    <!--按钮 -->
				    <g:button styleId="btnDelete" styleClass="delete" type="button" text="button.delete"/>
				  </div>
			   </form>
		    </div>
		  </div>
		  <!--搜索模块-->
		
		<div class="ModuleGrid">
		<div class="ModuleGridBorder">
		<!-- 表格内容开始 -->
		<!-- <div id="tableDivId"> -->
		<div id="gridRoleManager"></div>
		
		</div>
		<!-- 表格内容 结束 -->
		</div>
		</div>	
		
		<div>
				    <!-- 编辑区域 -->
				  <div class="ModuleEdit">
				    <div class="ModuleEditBorder">
					<div id="roleEditFormDiv" style="display:none;">
					<div class="ModuleSearchTitle"><g:label showColon="false" text="<%= CommonMessageDomain.TABEL_EDIT %>" /></div>
					    <form id="roleEditForm" onsubmit="return false;">
					    <input type="hidden" name="roleId" id="hiddenRoleId" >
						<table width="100%" class="ModuleEditInput">
								<tr>
								    <input type="hidden" name="keyId" value="" id="keyId">	
									<td width="10%"><g:label text="<%=RoleDomain.roleName_full%>" allowBlank="false"/></td>
									<td width="22%"><g:text property="roleName"></g:text></td>
									<td width="10%"><g:label text="<%=RoleDomain.roleDesc_full %>"/></td>
									<td width="22%"><g:text property="roleDesc"/></td>
									<td width="10%"><g:label text="<%=RoleDomain.roleType_full%>" allowBlank="false" /></td>
									<td width="22%">
										<g:combox kind="select" property="roleType">
											<g:option value="1">Active</g:option>
											<g:option value="2">Lock</g:option>
											<g:option value="3">Disable</g:option>
										</g:combox>
									</td>
								</tr>
								<tr>
									<td width="10%"><g:label text="<%=RoleDomain.officeCode_full %>" allowBlank="false"/></td>
									<td><g:combox kind="associate" property="officeCode" styleId="officeCode"></g:combox>
									</td>
									
									<td><g:label text="<%=RoleDomain.activeDate_full %>" allowBlank="false" /></td>
									<td><g:date property="activeDate" dateFormat="yyyy-MM-dd" /></td>
									<td><g:label text="<%=RoleDomain.expiredDate_full %>" allowBlank="false" /></td>
									<td><g:date property="expiredDate" dateFormat="yyyy-MM-dd"/></td>
								</tr>	
						</table>
						</form>
						<html:javascript formName="roleEditForm" />
					</div>
				    </div>
				  <!-- 编辑区域 -->
		</div>
	</div>
	</div>
	</body>
</html>